package com.jec.module.sysconfig.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jec.utils.Response;

import lombok.Getter;
import lombok.Setter;

/**
 * Created by jeremyliu on 09/10/2016.
 */
@Entity
@Table(name="zhwg_config_relay_business")
public class RelayBusiness implements NetUnitConfig, Serializable{

    
	private static final long serialVersionUID = -8883345573489170980L;
	/*
	@NoArgsConstructor
	public static class Entry {
		
		@Getter @Setter
		private int board;
		
		@Getter @Setter
		private int ts;
		
		//public void to
		
	}
	*/

	public final static String splitChar = "\\n|\\r\\n| |\\t";

    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment",strategy="increment")
    @Getter @Setter
    private int id;
    
    
	@Getter @Setter
    @Column(name="element_id")
    private int netunit;
	

	@Getter @Setter
	private String code;
	
	@Getter @Setter
	private String name;
	
	@Getter @Setter
	private boolean digital;
	
	
	@Getter @Setter
	private String entries = "";
	
    @Column(name="update_date")
    private Date updateDate;
    
 
    @Override
    public Response validate() {
        Response response = Response.Builder().status(Response.STATUS_SUCCESS);
        //if(type<1 || type>3)
        //    return response.message("业务类型不合法");
        return response.status(Response.STATUS_SUCCESS);
    }

    @Override
    public void setUpdateDate() {
        updateDate = new Date();
    }

    @JsonIgnore
    public String[] getEntryList(){
        if(entries.equals(""))
            return new String[0];
        return entries.split(splitChar);
    }

    public void setMembers(String members) {
        entries = members;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }
}
